package weixin.core.controller;

import com.github.sd4324530.fastweixin.api.MessageAPI;
import com.github.sd4324530.fastweixin.handle.EventHandle;
import com.github.sd4324530.fastweixin.handle.MessageHandle;
import com.github.sd4324530.fastweixin.message.BaseMsg;
import com.github.sd4324530.fastweixin.message.ImageMsg;
import com.github.sd4324530.fastweixin.message.VoiceMsg;
import com.github.sd4324530.fastweixin.message.req.*;
import com.github.sd4324530.fastweixin.servlet.WeixinControllerSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import weixin.core.Handles.MyMenuEvent;
import weixin.core.Handles.MyTextMessageHandle;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by lxb on 2015/12/22.
 */
@Controller
@RequestMapping("wechatController")
public class WeixinBaseController extends WeixinControllerSupport {
    private static final Logger LOG  = LoggerFactory.getLogger(WeixinBaseController.class);
    @Value(value = "${token}")
    private String token;
    @Value("${appid}")
    private String appid;
    @Autowired
    private MessageAPI messageAPI;
    @Autowired
    private MyMenuEvent myMenuEvent;
    @Autowired
    private MyTextMessageHandle myTextMessageHandle;
    @Override
    protected String getToken() {
        return this.token;
    }

    @Override
    protected String getAppId() {

        return this.appid;
    }

    /**
     * 微信消息拦截器
     * @return
     */
    @Override
    protected List<MessageHandle> initMessageHandles() {
        List<MessageHandle> handles = new ArrayList<MessageHandle>();
        handles.add(myTextMessageHandle);
        return handles;
    }

    @Override
    protected List<EventHandle> initEventHandles() {
        List<EventHandle> eventHandles=new ArrayList<EventHandle>();
        eventHandles.add(myMenuEvent);
        return eventHandles;
    }

    //处理图片消息
    @Override
    protected BaseMsg handleImageMsg(ImageReqMsg msg) {
        return new ImageMsg();
    }
    //处理语音消息
    @Override
    protected BaseMsg handleVoiceMsg(VoiceReqMsg msg) {
        return new VoiceMsg(null);
    }
    //发送视频消息
    @Override
    protected BaseMsg handleVideoMsg(VideoReqMsg msg) {
        return super.handleVideoMsg(msg);
    }
    //处理小视频
    @Override
    protected BaseMsg hadnleShortVideoMsg(VideoReqMsg msg) {
        return super.hadnleShortVideoMsg(msg);
    }
    //处理地理位置
    @Override
    protected BaseMsg handleLocationMsg(LocationReqMsg msg) {
        return super.handleLocationMsg(msg);
    }
    //处理链接消息
    @Override
    protected BaseMsg handleLinkMsg(LinkReqMsg msg) {
        return super.handleLinkMsg(msg);
    }
    //处理扫描二维码事件
    @Override
    protected BaseMsg handleQrCodeEvent(QrCodeEvent event) {
        return super.handleQrCodeEvent(event);
    }
    //处理地理位置事件
    @Override
    protected BaseMsg handleLocationEvent(LocationEvent event) {
        return super.handleLocationEvent(event);
    }
    //处理菜单点击事件
    @Override
    protected BaseMsg handleMenuClickEvent(MenuEvent event) {


        return super.handleMenuClickEvent(event);
    }
    //处理菜单跳转事件
    @Override
    protected BaseMsg handleMenuViewEvent(MenuEvent event) {
        return super.handleMenuViewEvent(event);
    }
    //处理菜单推送扫面事件
    @Override
    protected BaseMsg handleScanCodeEvent(ScanCodeEvent event) {
        return super.handleScanCodeEvent(event);
    }
    //处理弹出相册事件
    @Override
    protected BaseMsg handlePSendPicsInfoEvent(SendPicsInfoEvent event) {
        return super.handlePSendPicsInfoEvent(event);
    }
    //处理模板消息发送事件
    @Override
    protected BaseMsg handleTemplateMsgEvent(TemplateMsgEvent event) {
        return super.handleTemplateMsgEvent(event);
    }
    //处理添加关注事件
    @Override
    protected BaseMsg handleSubscribe(BaseEvent event) {
        return super.handleSubscribe(event);
    }
    //接收群发消息回调函数
    @Override
    protected BaseMsg callBackAllMessage(SendMessageEvent event) {
        return super.callBackAllMessage(event);
    }
    //处理取消关注事件
    @Override
    protected BaseMsg handleUnsubscribe(BaseEvent event) {
        return super.handleUnsubscribe(event);
    }

    @Override
    protected BaseMsg handleDefaultMsg(BaseReqMsg msg) {
        return super.handleDefaultMsg(msg);
    }

    @Override
    protected BaseMsg handleDefaultEvent(BaseEvent event) {
        return super.handleDefaultEvent(event);
    }

    @Override
    protected boolean isLegal(HttpServletRequest request) {
        return super.isLegal(request);
    }

}
